//import java.io.IOException;
//import java.io.PrintWriter;
//import java.net.URLDecoder;
//import java.net.URLEncoder;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.Cookie;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//@WebServlet("/LastVisit")
//public class LastVisitServlet extends HttpServlet {
//    @Override
//    protected void doGet(HttpServletRequest request, HttpServletResponse resp)
//            throws ServletException, IOException {
//        resp.setContentType("text/html;charset=UTF-8");
//
//        // 获取所有cookies
//        Cookie[] cookies = request.getCookies();
//        String lastVisitTime = null;
//
//        // 判断是否有上次访问的时间cookie
//        if (cookies != null) {
//            for (Cookie cookie : cookies) {
//                if ("lastVisit".equals(cookie.getName())) {
//                    lastVisitTime = URLDecoder.decode(cookie.getValue());
//                    break;
//                }
//            }
//        }
//
//        // 如果是首次访问，显示首次访问信息
//        if (lastVisitTime == null) {
//            resp.getWriter().write("Welcome! This is your first visit.");
//        } else {
//            resp.getWriter().write("Welcome back! Your last visit was: " + lastVisitTime);
//        }
//
//        // 设置当前时间并保存到cookie
//        String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
//        Cookie newCookie = new Cookie("lastVisit", URLEncoder.encode(currentTime));
//        resp.addCookie(newCookie);
//
//
//    }
//}
